<?php
namespace app\api_wp_v01\controller;

class Staff extends ApiWechatProgram {
	
	protected $staff_id;
	protected $staff_info;
	
	public function __construct() {
		
		parent::__construct();
		
		// 检查员工
		$result = $this->checkStaff($message);
		if(true !== $result){
			$this->returnError(9, $message);
		};
	}
	
	/**
	 * 检查员工
	 */
	private function checkStaff(&$message = '') {
		
		$SubscriberModel = \app\common\model\SubscriberModel::get($this->subscriber_id);
		if(null === $SubscriberModel){
			$message = '对应订阅者的信息未找到';
			return false;
		}else if(0 == $SubscriberModel->staff_id){
			$message = '您目前不是员工';
			return false;
		};
		
		$StaffModel = \app\common\model\StaffModel::get($SubscriberModel->staff_id);
		if((null === $StaffModel) || (0 !== $StaffModel->is_del)){
			$message = '对应的员工账号未找到';
			return false;
		};
		
		$this->staff_id = $StaffModel->id;
		$this->staff_info = $StaffModel->toArray();
		return true;
		
	}
	
}